//
//  XMSearchBar.m
//  XMWeibo
//
//  Created by chi on 14-8-21.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "XMSearchBar.h"



@implementation XMSearchBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self setBackground:[UIImage stretchableImageWithName:@"searchbar_textfield_background"]];
        
        
        //显示清除按钮
        [self setClearButtonMode:UITextFieldViewModeAlways];
        
        [self setContentMode:UIViewContentModeCenter];
        //设置文本框字体
        [self setFont:[UIFont systemFontOfSize:15]];
        
        //纵向对齐
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        
        //设置左边视图
        self.leftView = [[UIImageView alloc]initWithImage:[UIImage adaptIOS7ImageWithName:@"searchbar_textfield_search_icon"]];
        CGRect bounds = self.leftView.bounds;
        bounds.size.width += 15.0;
        self.leftView.bounds = bounds;
        self.leftView.contentMode = UIViewContentModeCenter;
        
        self.leftViewMode = UITextFieldViewModeAlways;
        
        NSMutableDictionary *attStr = [NSMutableDictionary dictionary];
        
        attStr[NSForegroundColorAttributeName] = [UIColor orangeColor];
        
        NSAttributedString *placeholder = [[NSAttributedString alloc]initWithString:@"搜索" attributes:attStr];
        [self setAttributedPlaceholder:placeholder];
       
        //设置键盘回车显示字符串
        self.returnKeyType = UIReturnKeySearch;
        self.enablesReturnKeyAutomatically = YES;
    }
    return self;
}



@end
